<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" type="text/css" href="/css/plugins/layui-formSelect/formSelects-v4.css"/>
    <link rel="stylesheet" href="/css/plat-style.css" />
</head>
<body>

<div class="layui-container">
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 15px;">
            <c:if test="${level==1}">
                <form class="layui-form" id="industryAddForm">
                    <input type="hidden" name="id" value="${industry.id}">
                    <input type="hidden" id="firstId" value="${industry.firstIds}">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*&nbsp;</span>行业名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" autocomplete="off" class="layui-input" value="${industry.name}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*&nbsp;</span>一级分类</label>
                        <div class="layui-input-block">
                            <select class="select chosen-select" multiple name="firstIds"
                                    id="firstIds" xm-select="firstIds">
                                <c:forEach items="${firstList}" var="f">
                                    <option value="${f.id}">${f.name}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>
                    <%--<div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*&nbsp;</span>行业范围</label>
                        <div class="layui-input-block">
                            <select class="select" name="onOff">
                                <c:forEach items="${scopeList}" var="s">
                                    <option value="${s.id}" ${industry.onOff==s.id?'selected':''} ${s.id==2?'disabled':''}>${s.name}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>--%>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*&nbsp;</span>行业图片</label>
                        <div class="layui-input-block">
                            <label for="imgUrl" class="layui-btn layui-btn-sm layui-btn-primary">上传图片</label>
                            <input accept=".jpg,.png,.gif,.jpeg" type="file" style="display:none;" name="imgUrl" id="imgUrl"
                                   onchange="showImg(this)"/>
                            <img id="img" src="${industry.url==null?' ':industry.url}" width="135px" height="135"/><br>
                            <span class="green">建议上传100*50尺寸大小的图片,格式支持jpg，png等;该值为非必填，若无图片可选择不上传</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*&nbsp;</span>排序</label>
                        <div class="layui-input-block">
                            <input type="text" name="sort" autocomplete="off" class="layui-input" value="${industry.sort}">
                            <span class="green">排序越高越靠前,格式为:数字0-9，不能包含其他字符</span>
                        </div>
                    </div>
                </form>
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <button class="layui-btn" onclick="FormSubmit('#industryAddForm','/product/editIndustry')">保存</button>
                        </div>
                    </div>
                </div>
            </c:if>
            <%--  子行业--%>
            <c:if test="${level==2}">
                <form class="layui-form" id="industryDetailAddForm">
                    <input type="hidden" name="id" value="${industryDetail.id}">
                    <input type="hidden" name="indId" value="${indId}">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*&nbsp;</span>明细名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" autocomplete="off" class="layui-input" value="${industryDetail.name}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*&nbsp;</span>明细图片</label>
                        <div class="layui-input-block">
                            <label for="detailUrl" class="layui-btn layui-btn-sm layui-btn-primary">上传图片</label>
                            <input accept=".jpg,.png,.gif,.jpeg" type="file" style="display:none;" name="imgUrl" id="detailUrl"
                                   onchange="showImg(this)"/>
                            <img id="detailImg" src="${industryDetail.url==null?' ':industryDetail.url}" width="135px" height="135"/><br>
                            <span class="green">建议上传100*50尺寸大小的图片,格式支持jpg，png等;该值为非必填，若无图片可选择不上传</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*&nbsp;</span>排序</label>
                        <div class="layui-input-block">
                            <input type="text" name="sort" autocomplete="off" class="layui-input" value="${industryDetail.sort}">
                            <span class="green">排序越高越靠前,格式为:数字0-9，不能包含其他字符</span>
                        </div>
                    </div>
                </form>
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <button class="layui-btn" onclick="FormSubmit('#industryDetailAddForm','/product/editIndustryDetail')">保存</button>
                        </div>
                    </div>
                </div>
            </c:if>
        </div>
    </div>
</div>
<input type="hidden" id="level" value="${level}">
<script src="/layuiadmin/layui/layui.js"></script>
<script type="text/javascript" src="/js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery.form.js"></script>
<script type="text/javascript" src="/js/common.js"></script>
<script type="text/javascript" src="/js/plugins/image/previewImg.js"></script>
<script type="text/javascript" src="/js/plugins/layui-formSelect/formSelects-v4.min.js"></script>
<script>
    layui.config({
        //静态资源所在路径
        base: '/layuiadmin/'
    }).extend({
        //主入口模块
        index: 'lib/index'
    }).use(['index', 'form'], function(){
        var $ = layui.$,layer = layui.layer,element = layui.element;
        element.render();
    });

    $(function () {
        // layui多选插件加载
        var formSelects = layui.formSelects;
        formSelects.value('firstIds');
        var level = $("#level").val();
        if(level == 1){
            var ids = $("#firstId").val();
            showClassify(ids);
        }
    });

    function showClassify(ids){
        var formSelects = layui.formSelects;
        var arr = [];
        for(var i = 0,len = ids.length; i< len;i++){
            arr.push(ids[i]);
        }
        formSelects.value('firstIds', arr);
    }
</script>
</body>
</html>